package com.ruoyi.web.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.domain.dto.UserMessageDto;
import com.ruoyi.web.domain.vo.UserMessageVo;
import com.ruoyi.web.service.IUserMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "用户留言控制层")
@RequestMapping("/userMessage")
public class UserMessageController extends BaseController {

    @Autowired
    private IUserMessageService userMessageService;

    @PostMapping
    @ApiOperation("留言")
    public AjaxResult leaveMsg(@RequestBody UserMessageDto dto) {
        return userMessageService.leaveMsg(dto);
    }

    @GetMapping("/list")
    @ApiOperation("查询用户留言列表")
    public TableDataInfo getList(UserMessageDto dto) {
        startPage();
        List<UserMessageVo> list = userMessageService.getList(dto);
        return getDataTable(list);
    }

    @DeleteMapping
    @ApiOperation("删除用户留言")
    public AjaxResult delete(UserMessageDto dto) {
        return userMessageService.delete(dto);
    }

    @GetMapping("/messageCount")
    @ApiOperation("查询留言数量数据统计")
    public AjaxResult getUserMessageCount() {
        return AjaxResult.success(userMessageService.getUserMessageCount());
    }
}
